<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BasePatientRelativeDetails.class.php';

Class PatientRelativeDetails {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjPatientRelativeDetails = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientRelativeDetails = new BasePatientRelativeDetails();
			$objPatientRelativeDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientRelativeDetails->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objPatientRelativeDetails->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objPatientRelativeDetails->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objPatientRelativeDetails->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objPatientRelativeDetails->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objPatientRelativeDetails->setPatientRelationship( ( true == isset( $row["patient_relationship"] ) ) ? $row["patient_relationship"] : 'NULL' );
			$objPatientRelativeDetails->setProfilePhotoPath( ( true == isset( $row["profile_photo_path"] ) ) ? $row["profile_photo_path"] : 'NULL' );
			$objPatientRelativeDetails->setAddressProof( ( true == isset( $row["address_proof"] ) ) ? $row["address_proof"] : 'NULL' );
			array_push( $arrobjPatientRelativeDetails, $objPatientRelativeDetails );
		}
		return $arrobjPatientRelativeDetails;
	}
	public function fetchAllPatientRelativeDetails() {
		$result = $this->connection->RunQuery("SELECT * FROM PATIENT_RELATIVE_DETAILS");
		$arrobjPatientRelativeDetails = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientRelativeDetails = new BasePatientRelativeDetails();
			$objPatientRelativeDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientRelativeDetails->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objPatientRelativeDetails->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objPatientRelativeDetails->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objPatientRelativeDetails->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objPatientRelativeDetails->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objPatientRelativeDetails->setPatientRelationship( ( true == isset( $row["patient_relationship"] ) ) ? $row["patient_relationship"] : 'NULL' );
			$objPatientRelativeDetails->setProfilePhotoPath( ( true == isset( $row["profile_photo_path"] ) ) ? $row["profile_photo_path"] : 'NULL' );
			$objPatientRelativeDetails->setAddressProof( ( true == isset( $row["address_proof"] ) ) ? $row["address_proof"] : 'NULL' );
			array_push( $arrobjPatientRelativeDetails, $objPatientRelativeDetails);
		}
		return $arrobjPatientRelativeDetails;
	}
	public function fetchAllPatientRelativeDetailsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM PATIENT_RELATIVE_DETAILS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjPatientRelativeDetails = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientRelativeDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientRelativeDetails->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objPatientRelativeDetails->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objPatientRelativeDetails->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objPatientRelativeDetails->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objPatientRelativeDetails->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objPatientRelativeDetails->setPatientRelationship( ( true == isset( $row["patient_relationship"] ) ) ? $row["patient_relationship"] : 'NULL' );
			$objPatientRelativeDetails->setProfilePhotoPath( ( true == isset( $row["profile_photo_path"] ) ) ? $row["profile_photo_path"] : 'NULL' );
			$objPatientRelativeDetails->setAddressProof( ( true == isset( $row["address_proof"] ) ) ? $row["address_proof"] : 'NULL' );
			array_push( $arrobjPatientRelativeDetails, $objPatientRelativeDetails );
		}
		return $arrobjPatientRelativeDetails;
	}

	public function fetchPatientRelativeDetailsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM PATIENT_RELATIVE_DETAILS WHERE id = " . $intId );
			$objPatientRelativeDetails = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientRelativeDetails = new BasePatientRelativeDetails();
			$objPatientRelativeDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientRelativeDetails->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objPatientRelativeDetails->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objPatientRelativeDetails->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objPatientRelativeDetails->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objPatientRelativeDetails->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine1( ( true == isset( $row["address_line1"] ) ) ? $row["address_line1"] : 'NULL' );
			$objPatientRelativeDetails->setAddressLine2( ( true == isset( $row["address_line2"] ) ) ? $row["address_line2"] : 'NULL' );
			$objPatientRelativeDetails->setPatientRelationship( ( true == isset( $row["patient_relationship"] ) ) ? $row["patient_relationship"] : 'NULL' );
			$objPatientRelativeDetails->setProfilePhotoPath( ( true == isset( $row["profile_photo_path"] ) ) ? $row["profile_photo_path"] : 'NULL' );
			$objPatientRelativeDetails->setAddressProof( ( true == isset( $row["address_proof"] ) ) ? $row["address_proof"] : 'NULL' );
		}
		return $objPatientRelativeDetails;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from patient_relative_details order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endPatientRelativeDetails(){
		$this->connection->CloseMysql();
	}

}